<?php
/**
 * class oeCategory
 * @method string getId()
 * @method string getName()
 * @method string getCategoryId()
 * @method string getStatus()
 * @method string setName()
 * @method string setCategoryId()
 * @method string setStatus()
 */
class oeCategory extends DbObject {
	
	const CATEGORY_STATUS_VISIBLE = 0;
	const CATEGORY_STATUS_HIDDEN = 1;
	
	public static function create($params) {
		
		$obj = new oeCategory();
		if (isset($params['id']))
			$obj = new oeCategory($params['id']);
		$obj->setName($params['name']);
		if (isset($params['categoryId']))
			$obj->setCategoryId($params['categoryId']);
		$obj->setStatus($params['status']);
		$obj->commit();
		return $obj->getId();
	}
	
	public function getQuestions() {
		
	}
	
	public function getSubCategories() {
		return db::getInstance()->getObjects('oeCategory', '`categoryId`=:categoryId AND `status`=:visible', array('categoryId' => $this->getId(), 'visible' => oeCategory::CATEGORY_STATUS_VISIBLE ));
	}
	
	public function isParentCategory() {
		return is_null($this->getCategoryId());
	}
	
	public function isVisible() {
		return ($this->getStatus() == oeCategory::CATEGORY_STATUS_VISIBLE);
	}
}
